package com.restkeeper.store.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.restkeeper.store.entity.CreditLogs;
import com.restkeeper.store.mapper.CreditLogMapper;
import org.apache.dubbo.config.annotation.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;

@org.springframework.stereotype.Service("creditLogsService")
@Service(version = "1.0.0",protocol = "dubbo")
public class CreditLogsServiceImpl extends ServiceImpl<CreditLogMapper, CreditLogs> implements  ICreditLogsService{

    @Override
    public IPage<CreditLogs> queryPage(String creditId, int page, int pageSize, LocalDateTime startTime, LocalDateTime endTime) {
        IPage<CreditLogs> iPage = new Page<>(page,pageSize);
        QueryWrapper<CreditLogs> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(CreditLogs::getCreditId,creditId)
                .ge(startTime != null,CreditLogs::getLastUpdateTime,startTime)
                .le(endTime != null,CreditLogs::getLastUpdateTime,endTime)
                .orderByDesc(CreditLogs::getLastUpdateTime);
        return this.page(iPage,queryWrapper);
    }
}